<?php
	//接收前端的数据添加到数据库
	
	$name = $_GET['name'];
	$price = $_GET['price'];
	$num = $_GET['num'];
	
	//链接数据库
	$conn=mysqli_connect('localhost','root','root','mydate');
	//设置链接过程中存取数据的编码
	mysqli_query($conn,"set charset 'utf8'");
	mysqli_query($conn,"set character set 'utf8'");
	
	//编写sql语句
	$sql = "insert into shop2 (name,price,num) values ('$name',$price,$num)";
	
	
	// $sql="insert into dates (name,pwd,age) value ('add','66',123)";
	// 3.执行sql语句
	// 现在这种情况res得到的是一个布尔值
	$res=mysqli_query($conn,$sql);
	// 判断是否成功插入数据
	
	if($res){
		echo json_encode(array(
			"code" => 200,
			"body" => array(
				"msg" => "添加成功"
			)
		));
	}else{
		echo json_encode(array(
			"code" => 201,
			"body" => array(
				"msg" => "添加失败"
			)
		));
	}
?>